#!/usr/bin/python3.8.9
# -*- coding: utf-8 -*-

# @Author  : Tina Yu
# @Time    : 2022-5-4 15:11
import os

import yaml


class ReadFile:

    @classmethod
    def get_file_path(cls):
        """获取当前文件的上级-->再上级 的目录路径(相当于是项目的根目录路径）"""
        return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    @classmethod
    def read_yaml(cls, file_name):
        """读取yaml文件"""
        _path = cls.get_file_path()
        # 拼接yaml文件所在的绝对路径 sep 相当于 win的 \ linux的/ sep.join 需要的参数是一个列表
        yaml_path = os.sep.join([_path, "datas", f'{file_name}.yaml'])
        with open(yaml_path, 'r', encoding='utf-8') as f:
            return yaml.safe_load(f)


if __name__ == '__main__':
    read_file = ReadFile()
    yaml_result = read_file.read_yaml('corp_info')
    print(yaml_result['corp_id']['manmiaoxuan'])
    print(yaml_result['corp_secret']['contactsApi'])
